#include <bits/stdc++.h>
using namespace std;
int t,n;
char type[20];
char name[15];
typedef long long ll;
int main(void){
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        ll sum=0;
        while(n--){
            scanf("%s %s",type,name);
            if(type[0]=='l'){
                scanf("%s",name);
            }
            if(type[0]=='i'){
                sum+=4;
            }else if(type[0]=='b'){
                sum+=1;
            }else if(type[0]=='l'){
                sum+=8;
            }else if(type[0]=='d'){
                sum+=8;
            }else if(type[0]=='c'){
                sum+=1;
            }else if(type[0]=='f'){
                sum+=4;
            }
        }
        printf("%lld\n",(sum+1023)/1024);
    }
    return 0;
}